<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
    request.setAttribute("basePath", basePath);
%>
<!DOCTYPE>
<html>
<head>
    <title>子用户界面</title>
    <%@ include file="/resources/js/easyui/taglibs.jsp" %>
    <%@ include file="/resources/js/easyui/_easyui.jsp" %>
    <%@ include file="/resources/js/easyui/_message.jsp" %>
    <%@ include file="/resources/js/easyui/_viewJS.jsp" %>
</head>

<body>

<div id="tb" style="padding:5px;height:auto;">
    <table>
        <tr>
            <td><label style="margin-left:5px">有效期:</label></td>
            <td><input class="easyui-datebox" id="stime"/> &nbsp;到&nbsp;
                <input class="easyui-datebox" id="etime"/></td>

            <td><a href="javascript:;"
                   style="margin-left: 10px;vertical-align:middle"
                   class="easyui-linkbutton" iconCls="icon-search" id="queryDataBtn">查询</a>
            </td>
        </tr>
    </table>

    <div id="button">
        <a href="javascript:void(0)" class="easyui-linkbutton" plain="true" iconCls="icon-add" id="addWinBtn">新增</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" plain="true" iconCls="icon-edit" id="editWinBtn">修改</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" plain="true" iconCls="icon-cancel" id="delBtn">删除</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" plain="true" iconCls="icon-add" id="setupWinBtn">分配角色</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" plain="true" iconCls="icon-add"
           id="setupShortCodeWinBtn">设置用户短码</a>
        <%--<a href="javascript:void(0)" class="easyui-linkbutton" plain="true" iconCls="icon-add"
           id="setupBusinessInfoWinBtn">设置用户商户号</a>--%>
    </div>

</div>

<table id="dg" title="子用户列表" fitColumns="true"
       data-options="
	   pageList:[5,10,15,20],
       pageSize:5,
       toolbar:'#tb',
       pagination:true,
       singleSelect:true,
       collapsible:true,
       url:'${basePath}web/childuser/list.json',
       method:'GET',
       rownumbers:false">
    <thead>
    <tr>
        <th data-options="field:'userid',checkbox:true,width:10"></th>
        <th data-options="field:'roleNameCN' ,width:40" align="center">用户组</th>
        <th data-options="field:'username' ,width:40" align="center">用户名</th>
        <th data-options="field:'mobile' ,width:40" align="center">移动电话</th>
        <th data-options="field:'shortcode' ,width:60" align="center">用户简码</th>
        <th data-options="field:'state' ,width:30" align="center"
            formatter="useState">状态
        </th>
        <th data-options="field:'mobileconfirmed' ,width:30"
            formatter="mobileConifrmedState" align="center">手机验证
        </th>
        <th data-options="field:'emailconfirmed' ,width:30"
            formatter="emailConifrmedState" align="center">邮件验证
        </th>
        <th data-options="field:'remark' ,width:110" align="center">备注</th>
        <!-- <th data-options="field:'removeuser',width:100"
            formatter="genDetailLink" align="center">操作</th> -->
    </tr>
    </thead>
</table>

<!-- 添加窗体s -->
<div id="addWin" class="easyui-window" minimizable="false"
     collapsible="false" title="新增子用户窗口"
     data-options="closed:true,modal:true,top:20"
     style="width:660px;height:526px;">
    <div id="addWinDetailTable" class="easyui-layout"
         data-options="fit:true">
        <div data-options="region:'center',border:false"></div>
        <div data-options="region:'south',border:false"
             style="text-align:center;padding:5px 5px 5px 0;background-color: #F5F5F5;border-top: solid 1px #E6E6E6;">
            <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'"
               href="javascript:void(0)" id="addSubBtn">提交</a> <a
                class="easyui-linkbutton" data-options="iconCls:'icon-cancel'"
                href="javascript:void(0)" id="closeAddWinBtn">关闭</a>
        </div>
    </div>
</div>
<!-- 添加窗体e -->

<!-- 修改窗体s -->
<div id="editWin" class="easyui-window" minimizable="false"
     collapsible="false" title="编辑子用户窗口"
     data-options="closed:true,modal:true,top:20"
     style="width:600px;height:500px;">
    <div id="editWinDetailTable" class="easyui-layout"
         data-options="fit:true">
        <div data-options="region:'center',border:false"></div>
        <div data-options="region:'south',border:false"
             style="text-align:center;padding:5px 5px 5px 0;background-color: #F5F5F5;border-top: solid 1px #E6E6E6;">
            <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'"
               href="javascript:void(0)" id="editSubBtn">提交</a> <a
                class="easyui-linkbutton" data-options="iconCls:'icon-cancel'"
                href="javascript:void(0)" id="closeEditWinBtn">关闭</a>
        </div>
    </div>
</div>
<!-- 修改窗体e -->

<!-- 设置窗体s -->
<div id="setupWin" class="easyui-window" minimizable="false"
     collapsible="false" title="分配角色窗口"
     data-options="closed:true,modal:true,top:20"
     style="width:600px;height:500px;">
    <div id="setupWinDetailTable" class="easyui-layout"
         data-options="fit:true">
        <div data-options="region:'center',border:false"></div>
        <div data-options="region:'south',border:false"
             style="text-align:center;padding:5px 5px 5px 0;background-color: #F5F5F5;border-top: solid 1px #E6E6E6;">
            <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'"
               href="javascript:void(0)" id="setupSubBtn">提交</a> <a
                class="easyui-linkbutton" data-options="iconCls:'icon-cancel'"
                href="javascript:void(0)" id="closeSetupWinBtn">关闭</a>
        </div>
    </div>
</div>
<!-- 设置窗体e -->

<!-- 设置用户短码窗体s -->
<div id="setupUserShortCodeWin" class="easyui-window" minimizable="false"
     collapsible="false" title="设置用户短码窗口"
     data-options="closed:true,modal:true,top:20"
     style="width:500px;height:250px;">
    <div id="setupUserShortCodeWinDetailTable" class="easyui-layout"
         data-options="fit:true">
        <div data-options="region:'center',border:false"></div>
        <div data-options="region:'south',border:false"
             style="text-align:center;padding:5px 5px 5px 0;background-color: #F5F5F5;border-top: solid 1px #E6E6E6;">
            <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'"
               href="javascript:void(0)" id="setupUserShortCodeSubBtn">提交</a> <a
                class="easyui-linkbutton" data-options="iconCls:'icon-cancel'"
                href="javascript:void(0)" id="closesetupUserShortCodeWinBtn">关闭</a>
        </div>
    </div>
</div>
<!-- 设置用户短码窗体s -->

<!-- 设置用户商户信息窗体s -->
<div id="setupBusinessInfoWinWin" class="easyui-window" minimizable="false"
     collapsible="false" title="设置用户商户信息窗口"
     data-options="closed:true,modal:true,top:20"
     style="width:500px;height:250px;">
    <div id="setupBusinessInfoWinDetailTable" class="easyui-layout"
         data-options="fit:true">
        <div data-options="region:'center',border:false"></div>
        <div data-options="region:'south',border:false"
             style="text-align:center;padding:5px 5px 5px 0;background-color: #F5F5F5;border-top: solid 1px #E6E6E6;">
            <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'"
               href="javascript:void(0)" id="setupBusinessInfoWinSubBtn">提交</a> <a
                class="easyui-linkbutton" data-options="iconCls:'icon-cancel'"
                href="javascript:void(0)" id="closeSetupBusinessInfoWinBtn">关闭</a>
        </div>
    </div>
</div>
<!-- 设置用户商户信息窗体s -->

</body>

<script type="text/javascript">
    function View() {
        var that = this;

        that.events = [
            {sel: '#queryDataBtn', act: 'click', func: 'queryData'},
            {sel: '#addWinBtn', act: 'click', func: 'addWin'},
            {sel: '#addSubBtn', act: 'click', func: 'addSub'},
            {sel: '#closeAddWinBtn', act: 'click', func: 'closeAddWin'},
            {sel: '#editWinBtn', act: 'click', func: 'editWin'},
            {sel: '#editSubBtn', act: 'click', func: 'editSub'},
            {sel: '#closeEditWinBtn', act: 'click', func: 'closeEditWin'},
            {sel: '#setupWinBtn', act: 'click', func: 'setupWin'},
            {sel: '#setupSubBtn', act: 'click', func: 'setupSub'},
            {sel: '#closeSetupWinBtn', act: 'click', func: 'closeSetupWin'},
            {sel: '#delBtn', act: 'click', func: 'delSub'},
            {sel: '#setupShortCodeWinBtn', act: 'click', func: 'openUserShortCodeWin'},
            {sel: '#setupUserShortCodeSubBtn', act: 'click', func: 'saveUserShortCodeSub'},
            {sel: '#closesetupUserShortCodeWinBtn', act: 'click', func: 'closeUserShortCodeSubWin'},
            {sel: '#setupBusinessInfoWinBtn', act: 'click', func: 'openUserBusinessInfoWin'},
            {sel: '#setupBusinessInfoWinSubBtn', act: 'click', func: 'saveBusinessInfoSub'},
            {sel: '#closeSetupBusinessInfoWinBtn', act: 'click', func: 'closeBusinessInfoWin'}];

        that.$dataGrid = $('#dg');
        that.$addWin = $('#addWin');
        that.$addWinDetailTable = $("#addWinDetailTable");

        that.$editWin = $('#editWin');
        that.$editWinDetailTable = $("#editWinDetailTable");

        that.$setupWin = $('#setupWin');
        that.$setupWinDetailTable = $("#setupWinDetailTable");

        that.$setupUserShortCodeWin = $('#setupUserShortCodeWin');
        that.$setupUserShortCodeWinDetailTable = $("#setupUserShortCodeWinDetailTable");

        that.$setupUserBusinessInfoWin = $('#setupBusinessInfoWinWin');
        that.$setupUserBusinessInfoWinDetailTable = $("#setupBusinessInfoWinDetailTable");

        that.dataGridOption = {};

        $.extend(that.dataGridOption, ViewHelper.template.gridOption);

        that.$dataGrid.datagrid(that.dataGridOption);

        that.queryData = function () {
            that.$dataGrid.datagrid(that.dataGridOption);
        };

        that.addWin = function () {
            var url = "${basePath}web/childuser/childuserAddView";
            that.$addWinDetailTable.layout('panel', 'center').find('iframe')
                    .remove();
            that.$addWinDetailTable
                    .layout('panel', 'center')
                    .append(
                            "<iframe id='add_iframe' name='info_iframe' width='100%' height='100%' frameborder='0'  src='"
                            + url + "'></iframe>");
            that.$addWin.dialog('open');
        };

        that.addSub = function () {
            $("#add_iframe")[0].contentWindow.add();
        };

        that.closeAddWin = function (result) {
            if (result == 1) {
                $.fn.window.defaults.top = 50;
                $.messager.alert('提示', '保存成功!', 'info');
            } else if (result == 0) {
                $.fn.window.defaults.top = 50;
                $.messager.alert('提示', '保存失败!', 'error');
            }
            that.$dataGrid.datagrid('reload');
            that.$addWin.window('close');
        };

        that.editWin = function () {
            var row = that.$dataGrid.datagrid('getSelected');
            if (row == null) {
                $.fn.window.defaults.top = 50;
                $.messager.alert('警告', '请选择一条', "error");
                return;
            }
            var url = "${basePath}web/childuser/" + row.userid
                    + "/childuserEditView";
            that.$editWinDetailTable.layout('panel', 'center').find('iframe')
                    .remove();
            that.$editWinDetailTable
                    .layout('panel', 'center')
                    .append(
                            "<iframe id='edit_iframe' name='info_iframe' width='100%' height='100%' frameborder='0'  src='"
                            + url + "'></iframe>");
            that.$editWin.dialog('open');
        };

        that.editSub = function () {
            $("#edit_iframe")[0].contentWindow.edit();
        };

        that.closeEditWin = function (result) {
            if (result == 1) {
                $.fn.window.defaults.top = 50;
                $.messager.alert('提示', '保存成功!', 'info');
            } else if (result == 0) {
                $.fn.window.defaults.top = 50;
                $.messager.alert('提示', '保存失败!', 'error');
            }
            that.$dataGrid.datagrid('reload');
            that.$editWin.window('close');
        };

        /* 分配权限窗体  */
        that.setupWin = function () {
            var row = that.$dataGrid.datagrid('getSelected');
            if (row == null) {
                $.fn.window.defaults.top = 50;
                $.messager.alert('警告', '请选择一条', "error");
                return;
            }
            var url = "${basePath}web/childuser/" + row.userid
                    + "/setupUserGroupView";
            that.$setupWinDetailTable.layout('panel', 'center').find('iframe')
                    .remove();
            that.$setupWinDetailTable
                    .layout('panel', 'center')
                    .append(
                            "<iframe id='setup_iframe' name='info_iframe' width='100%' height='100%' frameborder='0'  src='"
                            + url + "'></iframe>");
            that.$setupWin.dialog('open');
        };

        that.setupSub = function () {
            $("#setup_iframe")[0].contentWindow.setup();
        };

        that.closeSetupWin = function (result) {
            if (result == 1) {
                $.fn.window.defaults.top = 50;
                $.messager.alert('提示', '保存成功!', 'info');
            } else if (result == 0) {
                $.fn.window.defaults.top = 50;
                $.messager.alert('提示', '保存失败!', 'error');
            }
            that.$dataGrid.datagrid('reload');
            that.$setupWin.window('close');
        };
        /* 分配权限窗体 */

        that.delSub = function () {
            var row = that.$dataGrid.datagrid('getSelected');
            if (row == null) {
                $.fn.window.defaults.top = 50;
                $.messager.alert('警告', '请选择需要删除的数据');
                return;
            }
            var confirm, userid = row.userid;

            $.fn.window.defaults.top = 50;
            confirm = window.confirm('删除后数据不能恢复，确定要删除吗？');
            if (confirm) {
                $
                        .ajax({
                            url: '${basePath}web/childuser/' + userid
                            + '/removeChildUser',
                            type: 'DELETE',
                            data: {
                                "userid": userid
                            },
                            async: false, //默认为true 异步
                            traditional: true,
                            error: function () {
                                $.fn.window.defaults.top = 50;
                                $.messager.alert('提示', '删除失败', 'error');
                            },
                            success: function () {
                                $("#dg").datagrid('reload');
                                $.fn.window.defaults.top = 50;
                                $.messager.alert('提示', '删除成功', 'info');
                            }
                        });
            }
        };

        /* 设置用户短码窗体  */
        that.openUserShortCodeWin = function () {
            var row = that.$dataGrid.datagrid('getSelected');
            if (row == null) {
                $.fn.window.defaults.top = 50;
                $.messager.alert('警告', '请选择一条', "error");
                return;
            }
            var url = "${basePath}web/childuser/"+row.userid+"/showshortcode";
            that.$setupUserShortCodeWinDetailTable.layout('panel', 'center').find('iframe')
                    .remove();
            that.$setupUserShortCodeWinDetailTable
                    .layout('panel', 'center')
                    .append(
                            "<iframe id='add_usershortcode_iframe' name='info_iframe' width='100%' height='100%' frameborder='0'  src='"
                            + url + "'></iframe>");
            that.$setupUserShortCodeWin.dialog('open');
        };

        that.saveUserShortCodeSub = function () {
            $("#add_usershortcode_iframe")[0].contentWindow.addShort();
        };

        that.closeUserShortCodeSubWin = function (result) {
            if (result == 1) {
                $.fn.window.defaults.top = 50;
                $.messager.alert('提示', '保存成功!', 'info');
            } else if (result == 0) {
                $.fn.window.defaults.top = 50;
                $.messager.alert('提示', '保存失败!', 'error');
            }
            that.$dataGrid.datagrid('reload');
            that.$setupUserShortCodeWin.window('close');
        };
        /* 设置用户短码窗体 */

        /* 设置用户商业信息窗体  */
        that.openUserBusinessInfoWin = function () {
            var row = that.$dataGrid.datagrid('getSelected');
            if (row == null) {
                $.fn.window.defaults.top = 50;
                $.messager.alert('警告', '请选择一条', "error");
                return;
            }
            var url = "${basePath}web/childuser/"+row.userid+"/showUserBusinsessInfo";
            that.$setupUserBusinessInfoWinDetailTable.layout('panel', 'center').find('iframe')
                    .remove();
            that.$setupUserBusinessInfoWinDetailTable
                    .layout('panel', 'center')
                    .append(
                            "<iframe id='add_businessInfo_iframe' name='info_iframe' width='100%' height='100%' frameborder='0'  src='"
                            + url + "'></iframe>");
            that.$setupUserBusinessInfoWin.dialog('open');
        };

        that.saveBusinessInfoSub = function () {
            $("#add_businessInfo_iframe")[0].contentWindow.addBusinessInfo();
        };

        that.closeBusinessInfoWin = function (result) {
            if (result == 1) {
                $.fn.window.defaults.top = 50;
                $.messager.alert('提示', '保存成功!', 'info');
            } else if (result == 0) {
                $.fn.window.defaults.top = 50;
                $.messager.alert('提示', '保存失败!', 'error');
            }
            that.$dataGrid.datagrid('reload');
            that.$setupUserBusinessInfoWin.window('close');
        };
        /* 设置用户商业信息窗体 */

        EventHandler.call(that, that.events);

        return that;
    }

    var view;

    function genDetailLink(value, rowData, rowIndex) {
        return '<a class="GC_childusers_editchilduser" href="javascript:void(0)">编辑</a><a class="GC_childusers_removechilduser" href="javascript:void(0)">删除</a>';
    }

    function useState(value, row, index) {
        if (row.state == 0) {
            return "暂停";
        } else {
            return "启用";
        }
    }

    function mobileConifrmedState(value, row, index) {
        if (row.mobileconfirmed == 0) {
            return "未认证";
        } else {
            return "已认证";
        }
    }

    function emailConifrmedState(value, row, index) {
        if (row.emailconfirmed == 0) {
            return "未认证";
        } else {
            return "已认证";
        }
    }

    $(function () {
        inherit(View, EventHandler);
        view = new View();
    });
</script>

</html>